﻿using Nancy;
using Nancy.ModelBinding;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace customer.dao.V2
{
    public class SchemaLookupModel
    {
        public string DB { get; set; }


    }

    public class SchemaLookupModelBinder : IModelBinder
    {

        public object Bind(NancyContext context, Type modelType, object instance, BindingConfig configuration, params string[] blackList)
        {
            var queryModel = (instance as SchemaLookupModel) ?? new SchemaLookupModel();
            
            var db = context.Request.Headers["DB"].FirstOrDefault();
            if (!string.IsNullOrWhiteSpace(db))
                queryModel.DB = db;

            return queryModel;
        }

        public bool CanBind(Type modelType)
        {
            return modelType == typeof(SchemaLookupModel);
        }
    }

}
